package com.syq.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.syq.annotation.RequiresPermissionsDesc;
import com.syq.pojo.DtsAccountTrace;
import com.syq.pojo.DtsUser;
import com.syq.service.DtsAccountTraceService;
import com.syq.util.ResponseUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @ClassName: AccountTraceController
 * @Description: TODO
 * @Create by: syq
 * @Date: 2022/7/25 21:26
 */

@RestController
@RequestMapping("/admin/brokerage")
@CrossOrigin
public class AccountTraceController {

    @Autowired
    private DtsAccountTraceService dtsAccountTraceService;

    @RequiresPermissionsDesc(menu = {"用户管理","佣金管理"},button = "查询")
    @RequiresPermissions(value = "admin:brokerage:list")
    @GetMapping("/list")
    public Object userList(@RequestParam(defaultValue = "1") Integer page,
                           @RequestParam(defaultValue = "10") Integer limit, String mobile,Integer[] statusArray,String username,
                           @RequestParam(defaultValue = "add_time") String sort,
                           @RequestParam(defaultValue = "desc") String order){
        IPage<DtsAccountTrace> brokerageIPage=dtsAccountTraceService.findByPage(page,limit,username,statusArray,mobile,sort,order);
        Map<String,Object> map=new HashMap<>();
        map.put("total",brokerageIPage.getTotal());
        map.put("traceList",brokerageIPage.getRecords());
        return ResponseUtil.ok(map);
    }

    @RequiresPermissionsDesc(menu = {"用户管理","佣金管理"},button = "审批")
    @RequiresPermissions(value = "admin:brokerage:approve")
    @PostMapping("/approve")
    public Object approve(Integer id,Integer status){
        dtsAccountTraceService.updateStatus(id,status);
        return ResponseUtil.ok();
    }
}
